﻿using Microsoft.Practices.Unity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ymca.DataAccess;
using Ymca.DataAccess.Interfaces;
using Ymca.Entities;
using Ymca.Web.Services.Interfaces;

namespace Ymca.Web.Services
{
	public class ContentValuesService: IContentValuesService
	{
		private IDataContext _dataContext;

		public ContentValuesService()
		{
			_dataContext = new DataContext();
		}

		public ContentValue GetValue(string key)
		{
			return _dataContext.ContentValues.Find(key);
		}

		public void SetValue(string key, string value)
		{
			ContentValue contentValue = _dataContext.ContentValues.Find(key);
			if (contentValue != null)
			{
				contentValue.Value = value;
			}
			else
			{
				contentValue = new ContentValue(key, value);
				_dataContext.ContentValues.Add(contentValue);
			}
			_dataContext.Save();
		}
	}
}